package com.ruoyi.evaluate.infoprojectevaluateindex.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.attachment.domain.Attachment;
import com.ruoyi.attachment.service.IAttachmentService;
import com.ruoyi.evaluate.infoprojectevaluate.domain.InfoProjectEvaluate;
import com.ruoyi.evaluate.infoprojectevaluateindex.domain.InfoProjectEvaluateIndex;
import com.ruoyi.evaluate.infoprojectevaluateindex.service.IInfoProjectEvaluateIndexService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 自评中的指标Controller
 *
 * @author ruoyi
 * @date 2022-02-24
 */
@RestController
@RequestMapping("/infoProjectEvaluateIndex/infoProjectEvaluateIndex")
public class InfoProjectEvaluateIndexController extends BaseController {
    @Autowired
    private IInfoProjectEvaluateIndexService infoProjectEvaluateIndexService;
    @Resource
    private IAttachmentService attachmentService;

    /**
     * 查询自评中的指标列表
     */
    @PreAuthorize("@ss.hasPermi('infoProjectEvaluateIndex:infoProjectEvaluateIndex:list')")
    @GetMapping("/list")
    public TableDataInfo list(InfoProjectEvaluateIndex infoProjectEvaluateIndex) {
        startPage();
        List<InfoProjectEvaluateIndex> list = infoProjectEvaluateIndexService.selectInfoProjectEvaluateIndexList(infoProjectEvaluateIndex);
        return getDataTable(list);
    }

    /**
     * 导出自评中的指标列表
     */
    @PreAuthorize("@ss.hasPermi('infoProjectEvaluateIndex:infoProjectEvaluateIndex:export')")
    @Log(title = "自评中的指标", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InfoProjectEvaluateIndex infoProjectEvaluateIndex) {
        List<InfoProjectEvaluateIndex> list = infoProjectEvaluateIndexService.selectInfoProjectEvaluateIndexList(infoProjectEvaluateIndex);
        ExcelUtil<InfoProjectEvaluateIndex> util = new ExcelUtil<InfoProjectEvaluateIndex>(InfoProjectEvaluateIndex.class);
        util.exportExcel(response, list, "自评中的指标数据");
    }

    /**
     * 获取自评中的指标详细信息
     */
//    @PreAuthorize("@ss.hasPermi('infoProjectEvaluateIndex:infoProjectEvaluateIndex:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(infoProjectEvaluateIndexService.selectInfoProjectEvaluateIndexById(id));
    }

    /**
     * 新增自评中的指标
     */
    @PreAuthorize("@ss.hasPermi('infoProjectEvaluateIndex:infoProjectEvaluateIndex:add')")
    @Log(title = "自评中的指标", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InfoProjectEvaluateIndex infoProjectEvaluateIndex) {
        return toAjax(infoProjectEvaluateIndexService.insertInfoProjectEvaluateIndex(infoProjectEvaluateIndex));
    }

    /**
     * 修改自评中的指标
     */
//    @PreAuthorize("@ss.hasPermi('infoProjectEvaluateIndex:infoProjectEvaluateIndex:edit')")
    @Log(title = "自评中的指标", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InfoProjectEvaluateIndex infoProjectEvaluateIndex) {
        return toAjax(infoProjectEvaluateIndexService.updateInfoProjectEvaluateIndex(infoProjectEvaluateIndex));
    }



    /**
     * 删除自评中的指标
     */
    @PreAuthorize("@ss.hasPermi('infoProjectEvaluateIndex:infoProjectEvaluateIndex:remove')")
    @Log(title = "自评中的指标", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(infoProjectEvaluateIndexService.deleteInfoProjectEvaluateIndexByIds(ids));
    }

    /**
     * 上传文件
     */
    @RequestMapping(value = "/uploadFiles", method = RequestMethod.POST)
    public AjaxResult uploadFiles(@RequestBody InfoProjectEvaluateIndex infoProjectEvaluateIndex) {
        return toAjax(infoProjectEvaluateIndexService.uploadFiles(infoProjectEvaluateIndex));
    }

    /**
     * 上传佐证材料
     */
    @PostMapping(value = "/uploadProofFiles")
    public AjaxResult uploadProofFiles(@RequestBody Attachment attachment) {
        return toAjax(attachmentService.uploadServerFile(attachment,"info_project_evaluate_index"));
    }
}
